<?php
	include_once(dirname(__FILE__) . "/model/nms_alarm_model.php");
	include_once(dirname(__FILE__) . "/libs/nms_html_scripts.php");
	include_once(dirname(__FILE__) . "/libs/nms_html_views.php");
	function draw_nms_log_system(){
		html_master_script_filter();
		html_log_system_script();
		draw_nms_log_system_header();
		if (empty($_GET['filter'])) {
			$status="";
		}
		else{
			$status =  $_GET['filter'];
		}
		if (empty($_GET['record'])) {
			$record1="50";
		}
		else{
			$record1 =  $_GET['record'];
		}
		if (empty($_GET['search'])) {
			$search="";
		}
		else{
			$search =  $_GET['search'];
		}
			
		?>
		 		    <script type="text/javascript">
		 		    	$("#id_action_log_nms").val('<?php echo $status;?>');
		 		    	$("#id_record").val('<?php echo $record1;?>');
		 		    	$("#id_search1").val('<?php echo $search;?>');
		 		    </script>
		 <?php 
		$file = fopen("plugins/nms/log_nms/log_nms.txt", "r") or exit("Unable to open file!");
		//Output a line of the file until the end is reached
		//$test = '';
		while(!feof($file)) {
			draw_nms_log_system_table($file);
		}
		if (isset($_GET['search'])) {
			?>
					<script >
						var tmp = $('#id_master_table tr').removeHighlight().highlight('<?php echo trim($_GET['search']) ?>');
						alert(test);
						$('#id_master_table').empty();
						$('#id_master_table').html(test);
					</script>
					<?php 
					}
		html_master_footer_log_system();
 	}
 	 
 	function draw_nms_log_system_header(){
 	html_master_header_start("Log_NMS Filter");
?>
    		<table width="100%" border="0">
    			<tr>
	    		<!-- Status filter -->
	    			<td width="3%">Action:</td>
	    			<td width="5%">
		    			<select onchange="val()"  id="id_action_log_nms">
		    				<option value=""></option>
				        	<option value="1">Pause</option>
				            <option value="2">Unpause</option>
		        		</select>
	    			</td>
	  				<!-- Search -->
					<td>Search</td>
					<td colspan="3" scope="col">
	    				<input id="id_search1" type="search" onkeypress="keydown(event)"/>
	    			</td>
	    			<td>&nbsp;</td>
			    	<td>
			    		<input id="btnGo1" type="button" value="Go" ;">
			    	</td>
			    	<td>&nbsp;</td>
			    	<td>
			    		<input id="btnClear1" type="submit" name="clear_x" value="Clear" title="Clear Filters">
			    	</td>
			    	<td>&nbsp;</td>
			    	<td>&nbsp;</td>
					<td>
						<input id="btnRefresh1" type="button" value="Refresh" onclick="location.href='';">
					</td>
					<td width="3%">Record:</td>
	    			<td width="5%">
		    			<select onchange="val()"  id="id_record">
		    				<option value="50">Default</option>
				        	<option value="100">100</option>
				            <option value="200">200</option>
				            <option value="500">500</option>
				            <option value="1000">1000</option>
				            <option value="2000">2000</option>
				            <option value="3000">3000</option>
		        		</select>
	    			</td>
			    </tr>
    		</table> 		
   	<?php 
   	html_master_header_end();
 	}
 	function draw_nms_log_system_table($file){
		/* get value from action filter status*/
			$filtervalue=':';
			if(isset($_REQUEST['filter'])){
			if($_REQUEST['filter']=="1"){
				$filtervalue = "be paused by";
			}
			if($_REQUEST['filter']=="2"){
				$filtervalue = "be unpaused by";
			}
			}
			if(empty($_GET['record']))
			{
				$getrecord=50;
			}else{
				$getrecord=$_GET['record'];
			}
			if (!empty($_REQUEST['search'])) {
				$filtervalue=$_REQUEST['search'];
			}
		html_master_table_start("100%", "center");
 	?>
  			<tr class="cls_master_table_title" align="center">
  				<th width="2%" scope="col">No</th>
  				<th width="80%" scope="col">Information </th>
  			</tr>
  				<!-- play sound when devices down -->
					<?php
					$columns=0;
					while (false !== ($filename = fgets($file))) {
						$findme   = $filtervalue;
						//$findme1 = $research;
						$pos = strpos($filename, $findme);
						if ($pos === false) {}else {
							$files[] = $filename;
							$columns++;
						}
					}
					rsort($files);
					if($getrecord>$columns){
						$record = $columns;
					}else{
						$record=$getrecord;
					}
					$id=0;
					for($i=0;$i<$record;$i++){
						$id++;
						?>
						<tr <?php if($id%2==0) {echo 'class="xanhlot"';}
						 else {echo 'class="xanhdam"';}?>>
						 	<td align="center"><?php echo $id?> </td>
							<td >&nbsp;<?php echo $files[$i]?>
							</td>
						</tr>
						<?php 
					}
					?>
					<!-- thay doi mau cho cac trang thai trong bang -->
					<tr>
					  	<td >&nbsp;<?php   ?></td>		    	
	  				</tr>
			</table>
	</div>
<?php 	
 	}
 	function html_master_footer_log_system(){
?>
 	  	 		<div id="center_footer_up">
 					  	 	 			<div class="countdown_time"  >
 					  	 	 				<h3><div id="Timerefresh">Refresh time: </div></h3>
 					  	 	 				<h3><div id ="countdown_time2"></div></h3>
 					  	 	 			</div>
 				</div>
<?php 	
 	  	html_alarm_script_time();
 	  }
?>
 	 	